package com.psjj.mall.service.Impl;

import com.psjj.mall.exception.MallException;
import com.psjj.mall.exception.MallExceptionEnum;
import com.psjj.mall.mapper.UserMapper;
import com.psjj.mall.model.po.User;
import com.psjj.mall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Auther:云尚学Java
 */
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public void register(String userName, String password) {
        //判断用户是否存在
        User oldUser=userMapper.selectUserByUserName(userName);
            if(oldUser!=null){
                throw  new MallException(MallExceptionEnum.NAME_EXISTS);
            }
            User user=new User();
            user.setUsername(userName);
            user.setPassword(password);
            //添加失败
            int count=userMapper.insertSelective(user);
            if(count==0){
                throw  new MallException(MallExceptionEnum.INSERT_FAILED);
            }

    }
}
